<?php
namespace app\open\controller;
use app\common\controller\OpenBase;

class User extends OpenBase {
	protected $mod = '';
	protected function _initialize() {
		parent::_initialize();
		$this->mod = model('open/User');
	}
	/**
	 * @name 添加用户
	 */
	public function add() {
		//权限验证
		if (true !== self::checkAuth()) {
			return $this->getError();
		}
		$data = [
			'usid' => $this->usid,
			'uname' => $this->uname,
            'sex' => $this->sex
		];
		$res = $this->mod->addUser($data);
		if ($res === false) {
			return ['code' => '20001', 'message' => $this->mod->getError()];
		} else {
			return ['code' => '00000', 'data' => ['ticket' => $res]];
		}
	}
	/**
	 * @name 通过info-token兑换用户授权
	 */
	public function getUserAuthByTicket() {
		//兑换信息
		$auth = $this->mod->getUserAuthByTicket($this->ticket);
		if ($auth === false) {
			return ['code' => '10401', 'message' => $this->mod->getError()];
		}
		return $auth;
	}
	/**
	 * @name 未指定接口
	 */
	public function _empty($action = '') {
		if (strtolower($action) == 'getuserinfobyticket') {
			return $this->getUserAuthByTicket();
		}
		return getApiErrorCode('00404');
	}
}
